package com.yunxi.service.dubboService.impl;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageInfo;
import com.yunxi.baseDataToHub.pojo.urm.UserInfoVO;
import com.yunxi.baseDataToHub.service.urm.UrmDubboService;
import com.yunxi.bizToHub.pojo.CustomerSalesInfoVO;
import com.yunxi.bizToHub.service.VehicleStockManageDubboService;
import com.yunxi.core.enums.DMSEnumsEntity;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.DictConstant;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.customer.pojo.CustomCreditReportingVO;
import com.yunxi.customer.pojo.CustomerVO;
import com.yunxi.customer.service.CustomCreditReportingDubboService;
import com.yunxi.customer.service.CustomerDubboService;
import com.yunxi.dealer.pojo.ClientInfoVOFromURM;
import com.yunxi.dealer.pojo.PartnerVO;
import com.yunxi.dealer.service.PartnerDubboService;
import com.yunxi.finance.service.DynamicRebateCommissionDubboService;
import com.yunxi.hubToBiz.pojo.OrderActualSalesReqVO;
import com.yunxi.hubToBiz.pojo.OrderActualSalesRespVO;
import com.yunxi.hubToBiz.service.OrderActualSales2InsuranceDubboService;
import com.yunxi.model.order.OrderActualSales;
import com.yunxi.model.order.OrderCustomer;
import com.yunxi.model.order.PmsVehicleStock;
import com.yunxi.model.sat.HandleVehicle;
import com.yunxi.model.sto.VehicleOffline;
import com.yunxi.order.pojo.OrderActualSalesVO;
import com.yunxi.order.pojo.OrderCustomerDetailVO;
import com.yunxi.order.pojo.OrderCustomerVO;
import com.yunxi.order.pojo.ProductNameVO;
import com.yunxi.order.service.OrderActualSalesDubboService;
import com.yunxi.order.service.OrderCustomerDubboService;
import com.yunxi.sat.pojo.HandleVehicleVO;
import com.yunxi.sat.service.HandleVehicleDubboService;
import com.yunxi.service.localService.OrderActualSalesService;
import com.yunxi.service.localService.OrderCustomerService;
import com.yunxi.service.localService.sat.HandleVehicleService;
import com.yunxi.service.localService.sto.VehicleStockMService;
import com.yunxi.sto.pojo.VehicleOfflineVO;
import com.yunxi.sto.pojo.VehicleStockBindVO;
import com.yunxi.sto.service.VehicleOfflineDubboService;
import com.yunxi.sto.service.VehicleStockDubboService;
import com.yunxi.vehicle.pojo.VehicleCertVO;
import com.yunxi.vehicle.service.VehicleCertDubboService;
import com.yunxi.vip.pojo.VipVO;
import com.yunxi.vip.service.VipDubboService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 订单实销表 服务实现类
 * </p>
 *
 * @author
 * @since 2019-07-18
 */
public class OrderActualSalesDubboServiceImpl implements OrderActualSalesDubboService, OrderActualSales2InsuranceDubboService {
   private static final Logger logger = LoggerFactory.getLogger(OrderActualSalesDubboServiceImpl.class);

   @Autowired
   @Qualifier(value = "orderActualSalesServiceImpl")
   OrderActualSalesService orderActualSalesService;

   @Autowired
   OrderCustomerDubboService orderCustomerDubboServiceImpl;

   @Autowired
   CustomerDubboService customerDubboServiceImpl;

   @Autowired
   VehicleStockManageDubboService vehicleStockManageDubboServiceImpl;

   @Autowired
   PartnerDubboService partnerDubboServiceImpl;

   @Autowired
   HandleVehicleDubboService handleVehicleDubboServiceImpl;

   @Autowired
   VehicleOfflineDubboService vehicleOfflineDubboServiceImpl;

   @Autowired
   VipDubboService vipDubboServiceImpl;

   @Autowired
   DynamicRebateCommissionDubboService dynamicRebateCommissionDubboServiceImpl;

   @Autowired
   @Qualifier(value = "vehicleStockMServiceImpl")
   VehicleStockMService vehicleStockMService;

   @Autowired
   CustomCreditReportingDubboService customCreditReportingDubboServiceBase;

   @Autowired
   @Qualifier(value = "vehicleStockMServiceImpl")
   VehicleStockMService vehicleStockService;


   @Autowired
   @Qualifier(value = "orderCustomerServiceImpl")
   OrderCustomerService orderCustomerService;

   @Autowired
   VehicleStockDubboService vehicleStockDubboServiceImpl;

   @Autowired
   VehicleCertDubboService vehicleCertDubboServiceImpl;

   @Autowired
   UrmDubboService urmDubboServiceImplBiz;

   @Autowired
   @Qualifier(value = "handleVehicleServiceImpl")
   HandleVehicleService handleVehicleService;

   @Override
   public OrderActualSalesVO getById(String id) throws InvocationTargetException, IllegalAccessException {
      OrderActualSales orderActualSales = orderActualSalesService.getById(id);
      OrderActualSalesVO orderActualSalesVO = new OrderActualSalesVO();
      BeanUtils.copyProperties(orderActualSales, orderActualSalesVO);
      return orderActualSalesVO;
   }

   @Override
   public void saveOrUpdate(OrderActualSalesVO orderActualSalesVO) throws InvocationTargetException, IllegalAccessException {
      OrderActualSales orderActualSales = new OrderActualSales();
      BeanUtils.copyProperties(orderActualSalesVO, orderActualSales);
      orderActualSalesService.saveOrUpdate(orderActualSales);

      //Guan 2020-02-02
      OrderCustomerVO ocv = orderCustomerService.load(orderActualSales.getOrderCustomerNo());

      HandleVehicleVO hvv = handleVehicleService.getByOrderCustomerNo(orderActualSales.getOrderCustomerNo());

      if(ocv!=null&&ocv.getCustomerNo()==null&&StringUtils.isNotEmpty(orderActualSalesVO.getCustomerId())){
         ocv.setCustomerId(orderActualSalesVO.getCustomerId());
         ocv.setCustomerNo(orderActualSalesVO.getCustomerId());
         OrderCustomer oc = new OrderCustomer();
         BeanUtils.copyProperties(ocv,oc);
         orderCustomerService.updateById(oc);
      }

      if(StringUtils.isNotEmpty(orderActualSalesVO.getCustomerId())&&StringUtils.isEmpty(hvv.getCustomerNo())){
         hvv.setCustomerNo(orderActualSales.getCustomerId());
         HandleVehicle hv = new HandleVehicle();
         BeanUtils.copyProperties(hvv,hv);
         handleVehicleService.updateById(hv);
      }

   }

   @Override
   public void removeById(String id) {
      orderActualSalesService.removeById(id);
   }

   @Override
   public PageInfo<OrderActualSalesVO> findPageByVO(OrderActualSalesVO orderActualSalesVO, Integer pageNum, Integer pageSize, LoginInfo loginInfo) throws InvocationTargetException, IllegalAccessException {
      if (loginInfo.getPartner() != null) {
         orderActualSalesVO.setPartnerCode(loginInfo.getPartnerCode());

      } else {
//         orderActualSalesVO.setPartnerCode("");
//         orderActualSalesVO.setSalesConsultantNo("");
      }

      PageInfo<OrderActualSalesVO> pageInfo = orderActualSalesService.pageByVo(orderActualSalesVO, pageNum, pageSize);
      return pageInfo;
   }

   @Override
   public void removeByListVo(List<OrderActualSalesVO> orderActualSalesVOList) throws IllegalAccessException, InvocationTargetException, InstantiationException {
      orderActualSalesService.removeByListVo(orderActualSalesVOList);
   }

   @Override
   public List listByVo(OrderActualSalesVO orderActualSalesVO) {
      return orderActualSalesService.listByVo(orderActualSalesVO);
   }

   /**
    * 交车后生成实销数据
    *
    * @param orderCustomerNO 零售单号
    * @return
    */
   @Override
   @Transactional(rollbackFor = Exception.class)
   public ApiResult saveOrderActualSales(String orderCustomerNO, LoginInfo loginInfo) throws Exception {

      //零售订单数据
      OrderCustomerVO orderCustomerVO = orderCustomerDubboServiceImpl.load(orderCustomerNO);
      if (orderCustomerVO == null){
         throw new Exception("不存在该订单:"+orderCustomerNO);
      }
      //如果为体验车 不在交车后生成实销数据
      if (orderCustomerVO.getBuyType()== DMSEnumsEntity.OrderCustomerBuyType.HIRE.getCode()) {
         return ResponseUtil.ok();
      }else {
         QueryWrapper<OrderActualSales> wrapper = new QueryWrapper<>();
         wrapper.eq("VIN",orderCustomerVO.getVin());
         OrderActualSalesVO orderActualSalesVO = orderActualSalesService.loadDetail(orderCustomerNO);
         if (orderActualSalesVO!=null && StringUtils.isNotEmpty(orderActualSalesVO.getOrderCustomerId())){
            if (orderActualSalesVO.getIsCancelVehicle()==1){
               return ResponseUtil.ok();
            }else {
               throw new Exception("该车辆已实销"+orderCustomerVO.getVin());
            }
         }
      }
      //渠道商数据
      PartnerVO vo = new PartnerVO();
      if (StringUtils.isEmpty(orderCustomerVO.getPartnerCode())) throw new Exception("该订单:"+orderCustomerNO+"尚未分配渠道商:"+orderCustomerVO.getPartnerCode());
      vo.setPartnerCode(orderCustomerVO.getPartnerCode());
      List<PartnerVO> partnerVOList = partnerDubboServiceImpl.listByVo(vo);
      if (partnerVOList==null || partnerVOList.size()<=0) throw new Exception("不存在该渠道商:"+orderCustomerVO.getPartnerCode());
      PartnerVO partnerVO = partnerVOList.get(0);
      //交车数据
      HandleVehicleVO handleVehicleVO = new HandleVehicleVO();
      handleVehicleVO.setOrderCustomerNo(orderCustomerNO);
      List<HandleVehicleVO> handleVehicleVOList = handleVehicleDubboServiceImpl.listByVo(handleVehicleVO);
      if (handleVehicleVOList==null || handleVehicleVOList.size()<=0) throw new Exception("该订单尚未交车:"+orderCustomerNO);
      HandleVehicleVO handleVehicleVO1 = handleVehicleVOList.get(0);
      //车辆下线数据
      QueryWrapper<VehicleOffline> queryWrapper = new QueryWrapper<VehicleOffline>();
      queryWrapper.eq("VIN",orderCustomerVO.getVin());
      if (StringUtils.isEmpty(orderCustomerVO.getVin())) throw new Exception("该订单尚未配车:"+orderCustomerNO);
      VehicleOfflineVO vehicleOfflineVO = vehicleOfflineDubboServiceImpl.getOne(queryWrapper);
      if (vehicleOfflineVO==null) throw new Exception("不存在该下线车辆:"+orderCustomerVO.getVin());

      //购车方案 1-->购车 2-->体验车 3-->畅想车
      CustomerVO customerVO =null;
      if (orderCustomerVO.getBuyType()== DMSEnumsEntity.OrderCustomerBuyType.HIRE.getCode()){//2-->体验车
//         VipVO vipCustomer = vipDubboServiceImpl.getByVin(orderCustomerVO.getVin());
//         if (vipCustomer==null) throw new Exception("不存在该大客户信息:"+orderCustomerVO.getVin());
//         customerVO = new CustomerVO();
//         customerVO.setCustomerType("2");//客户类型(普通，企业/同CRM)
//         customerVO.setCustomerNo(vipCustomer.getVipNo());
//         customerVO.setName(vipCustomer.getVipName());
//         orderCustomerVO.setCompanyCode(vipCustomer.getCertNo());
      }else if (orderCustomerVO.getBuyType()==DMSEnumsEntity.OrderCustomerBuyType.BUY.getCode()){//1-->购车
         customerVO = customerDubboServiceImpl.getByPhone(orderCustomerVO.getCustomerMobile(), loginInfo.getPartnerCode());
         if (customerVO==null) throw new Exception("该渠道商"+loginInfo.getPartnerCode()+"不存在该客户信息:"+orderCustomerVO.getCustomerMobile());
         customerVO.setCustomerType("1");//客户类型(普通，企业/同CRM)
      }else {//3-->畅想车
         customerVO = customerDubboServiceImpl.getByPhone(orderCustomerVO.getCustomerMobile(), loginInfo.getPartnerCode());
         if (customerVO==null) throw new Exception("该渠道商"+loginInfo.getPartnerCode()+"不存在该客户信息:"+orderCustomerVO.getCustomerMobile());
         customerVO.setCustomerType("1");//客户类型(普通，企业/同CRM)
      }


      OrderActualSalesVO orderActualSalesVO = setOrderActualSales(orderCustomerVO, customerVO, partnerVO, handleVehicleVO1,vehicleOfflineVO);

      //体验车订单 更新实销数据
//      if (orderCustomerVO.getBuyType()== DMSEnumsEntity.OrderCustomerBuyType.HIRE.getCode()){
//         QueryWrapper<OrderActualSales> wrapper = new QueryWrapper<>();
//         wrapper.eq("VIN",orderCustomerVO.getVin());
//         List<OrderActualSales> list = orderActualSalesService.list(wrapper);
//         if (list!=null && list.size()>0){
//            OrderActualSales orderActualSales = list.get(0);
//            orderActualSalesVO.setOrderCustomerId(orderActualSales.getOrderCustomerId());
//         }
//      }
      orderActualSalesVO.setIsReported(0);//是否上报 0未上报 1已上报
      OrderActualSales orderActualSales = new OrderActualSales();
      BeanUtils.copyProperties(orderActualSalesVO, orderActualSales);
      orderActualSalesService.saveOrUpdate(orderActualSales);

      //实销完成后调用资金返利
      dynamicRebateCommissionDubboServiceImpl.keepAccounts(orderCustomerNO);
      return ResponseUtil.ok();
   }

   @Override
   public OrderActualSalesVO loadDetail(String orderCustomerNo) {
      return orderActualSalesService.loadDetail(orderCustomerNo);

   }

   @Override
   public void generateOrderActualInfo(String vin) {

      OrderActualSalesVO orderActualSalesVO = new OrderActualSalesVO();
//      orderActualSalesVO.setOrderCustomerId("");
//      orderActualSalesVO.setCustomerId("");
//      orderActualSalesVO.setCustomerName("");
//      orderActualSalesVO.setCustomerType("");
//      orderActualSalesVO.setUnitSocialCreditCode("");
//      orderActualSalesVO.setLegalPerson("");
//      orderActualSalesVO.setBuyerPerson("");
//      orderActualSalesVO.setIdType("");
//      orderActualSalesVO.setIdNumber("");
//      orderActualSalesVO.setSex("");
//      orderActualSalesVO.setAge(0);
//      orderActualSalesVO.setCompanyPhone("");
//      orderActualSalesVO.setPhone("");
//      orderActualSalesVO.setEmail("");
//      orderActualSalesVO.setAddress("");
//      orderActualSalesVO.setSaleAssist("");
//      orderActualSalesVO.setCarSaleStatus("");
      orderActualSalesVO.setVin(vin);
//      orderActualSalesVO.setSaleProvince("");
//      orderActualSalesVO.setSaleProvinceName("");
//      orderActualSalesVO.setSaleCityName("");
//      orderActualSalesVO.setSaleCity("");
//      orderActualSalesVO.setSaleCountryName("");
//      orderActualSalesVO.setSaleCountry("");
//      orderActualSalesVO.setCarNo("");
//      orderActualSalesVO.setSaleInternetNo("");
//      orderActualSalesVO.setSaleInternetName("");
//      orderActualSalesVO.setSalePrice("");
//      orderActualSalesVO.setPackagePrice("");
      orderActualSalesVO.setCarUsed("3");
//      orderActualSalesVO.setCreateRecordDate("");
//      orderActualSalesVO.setOpenInvoiceDate("");
//      orderActualSalesVO.setOutTime("");
//      orderActualSalesVO.setInvoiceNo("");
//      orderActualSalesVO.setUrgentName("");
//      orderActualSalesVO.setUrgentPhone("");
//      orderActualSalesVO.setCompany("");
//      orderActualSalesVO.setCompanyAddr("");
//      orderActualSalesVO.setDriverLicenseType("");
//      orderActualSalesVO.setDriverLicenseValidate("");
//      orderActualSalesVO.setLegalPersonPhone("");
//      orderActualSalesVO.setDriverLicenseNo("");
//      orderActualSalesVO.setOperationAddr("");
//      orderActualSalesVO.setStoreAddr("");
//      orderActualSalesVO.setStatus(0);

      QueryWrapper<PmsVehicleStock> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("VIN",vin);
      PmsVehicleStock vehicleStock = vehicleStockService.getOne(queryWrapper);
      orderActualSalesVO.setPartnerCode(vehicleStock.getPartnerCode());
//      orderActualSalesVO.setPartnerPhone("");
//      orderActualSalesVO.setPartnerAddr("");
//      orderActualSalesVO.setPartnerLinkMan("");
//      orderActualSalesVO.setBrandCode("");
//      orderActualSalesVO.setBrandName("");
      QueryWrapper<VehicleOffline> queryWrapper1 = new QueryWrapper<VehicleOffline>();
      queryWrapper1.eq("VIN",vin);
      VehicleOfflineVO vehicleOfflineVO = vehicleOfflineDubboServiceImpl.getOne(queryWrapper1);
      String productCode = vehicleOfflineVO.getProductCode();
      if (StringUtils.isNotEmpty(productCode)){
         String vehicleCode = productCode.substring(0, 15);
         orderActualSalesVO.setVehicleCode(vehicleCode);
         String colorCodeIn = productCode.substring(15, 19);
         String colorCodeOut = productCode.substring(19, 23);
         orderActualSalesVO.setColorInnerCode(colorCodeIn);
         orderActualSalesVO.setColorOutCode(colorCodeOut);
      }
      ProductNameVO productNameVO = orderCustomerService.getNameByVO(productCode);
      orderActualSalesVO.setVehicleName(productNameVO.getVehicleName());
      orderActualSalesVO.setColorOutName(productNameVO.getColorNameOut());
      orderActualSalesVO.setColorInnerName(productNameVO.getColorNameIn());
//      orderActualSalesVO.setEnguneNo("");
//      orderActualSalesVO.setMotorNo("");
//      orderActualSalesVO.setFrontMoney(new BigDecimal("0"));
//      orderActualSalesVO.setPrice(new BigDecimal("0"));
//      orderActualSalesVO.setPriceTypeName("");
//      orderActualSalesVO.setPriceTypeValue("");
//      orderActualSalesVO.setSettlementTypeCode("");
//      orderActualSalesVO.setSpecialConfig("");
//      orderActualSalesVO.setLicensePlateNumber("");
//      orderActualSalesVO.setYearlyInspectionDate("");
//      orderActualSalesVO.setYearlyInspectionCycle("");
//      orderActualSalesVO.setCertNo("");
//      orderActualSalesVO.setInterchange(new Date());
//      orderActualSalesVO.setCardDate(new Date());
//      orderActualSalesVO.setInsuranceDateRange("");
//      orderActualSalesVO.setInvoiceVehicleType("");
//      orderActualSalesVO.setBankAccount("");
//      orderActualSalesVO.setBank("");
//      orderActualSalesVO.setInvoiceBo("");
//      orderActualSalesVO.setInvoiceRate(new BigDecimal("0"));
//      orderActualSalesVO.setInsurerNo("");
//      orderActualSalesVO.setInsurerType("");
//      orderActualSalesVO.setDeliveryStartTime(new Date());
//      orderActualSalesVO.setDeliveryEndTime(new Date());
//      orderActualSalesVO.setStockOutStartTime(new Date());
//      orderActualSalesVO.setStockOutEndTime(new Date());
//      orderActualSalesVO.setOrderCustomerNo("");
//      orderActualSalesVO.setIsReported(0);
//      orderActualSalesVO.setBettaryCode("");
//      orderActualSalesVO.setElectronicControl("");
//      orderActualSalesVO.setIsBuyServicePack("");
//      orderActualSalesVO.setIsCancelVehicle(0);
//      orderActualSalesVO.setBuyCarType("");
//      orderActualSalesVO.setUser("");
//      orderActualSalesVO.setUserPhone("");
      orderActualSalesVO.setCustomPackCode(vehicleOfflineVO.getCustomPackCode());
      String packgeName = orderActualSalesService.getPackgeNameByPackgeCode(vehicleOfflineVO.getCustomPackCode());
      orderActualSalesVO.setCustomPackName(packgeName);
      orderActualSalesVO.setBuyType(2);
//      orderActualSalesVO.setPartnerName("");
//      orderActualSalesVO.setExpires("");
//      orderActualSalesVO.setDownPaymentRatio(0);
//      orderActualSalesVO.setSuretyAmount(new BigDecimal("0"));
//      orderActualSalesVO.setRetentionAmount(new BigDecimal("0"));
//      orderActualSalesVO.setVehiclePurpose(0);

   }

   private ApiResult queryUrmCustomerInfoByPhone(String phone, String partnerCode) {
      UserInfoVO userInfoVO = new UserInfoVO();
      userInfoVO.setMobile(phone);
      userInfoVO.setPartnerCode(partnerCode);
      ApiResult result = urmDubboServiceImplBiz.selectAccountByMobilePMS2Urm(userInfoVO);
      return result;
   }


   /**
    * 实销数据上报
    *
    * @param orderActualSalesVO
    * @return
    */
   @Override
   @Transactional
   public ApiResult salesReported(OrderActualSalesVO orderActualSalesVO, LoginInfo loginInfo) throws Exception {
      if (StringUtils.isEmpty(orderActualSalesVO.getVin())){
          return ResponseUtil.fail(-1,"VIN为空");
      }
      if (StringUtils.isEmpty(orderActualSalesVO.getPhone())){
         return ResponseUtil.fail(-1,"手机电话号为空");
      }
      if (StringUtils.isEmpty(orderActualSalesVO.getCustomerId())){
         //根据手机号查询 URM客户信息
         ApiResult apiResult = queryUrmCustomerInfoByPhone(orderActualSalesVO.getPhone(), orderActualSalesVO.getPartnerCode());
         if (apiResult.getCode()!=200) return apiResult;
         ClientInfoVOFromURM clientInfoVOFromURM = JSON.parseObject((String) apiResult.getData(), ClientInfoVOFromURM.class);
         if (clientInfoVOFromURM.getId()!=null){
            orderActualSalesVO.setCustomerId(String.valueOf(clientInfoVOFromURM.getId()));
         }else {
            return ResponseUtil.fail(-1,"根据手机号查询 URM客户信息返回客户id为空");
         }

      }
      OrderActualSales orderActualSales = new OrderActualSales();
      BeanUtils.copyProperties(orderActualSalesVO,orderActualSales);
      orderActualSales.setOrderCustomerId(orderActualSalesVO.getOrderCustomerId());
      orderActualSales.setIsReported(1);//上报
      orderActualSalesService.updateById(orderActualSales);

      // 更新零售订单 发票信息
       QueryWrapper<OrderCustomer> qw = new QueryWrapper<OrderCustomer>();
       qw.eq("ORDER_CUSTOMER_NO",orderActualSales.getOrderCustomerNo());


       OrderCustomer  orderCustomer = new OrderCustomer();

      //Guan 2020-02-02
      OrderCustomerVO ocv = orderCustomerService.getByOrderCustomerNo(orderActualSales.getOrderCustomerNo());

      HandleVehicleVO hvv = handleVehicleService.getByOrderCustomerNo(orderActualSales.getOrderCustomerNo());


      if(ocv!=null&&ocv.getCustomerNo()==null&&StringUtils.isNotEmpty(orderActualSalesVO.getCustomerId())){
         orderCustomer.setCustomerId(orderActualSalesVO.getCustomerId());
         orderCustomer.setCustomerNo(orderActualSalesVO.getCustomerId());
      }
      if(hvv!=null){
         if(StringUtils.isNotEmpty(orderActualSalesVO.getCustomerId())&&StringUtils.isEmpty(hvv.getCustomerNo())){
            hvv.setCustomerNo(orderActualSales.getCustomerId());
            HandleVehicle hv = new HandleVehicle();
            BeanUtils.copyProperties(hvv,hv);
            handleVehicleService.updateById(hv);
         }
      }

       orderCustomer.setOrderCustomerId(orderActualSales.getOrderCustomerId());
       orderCustomer.setInvoiceCode(orderActualSales.getInvoiceNo());
       SimpleDateFormat simpleDateFormat =new SimpleDateFormat("yyyy-MM-dd");
       Date  invoiceTime = simpleDateFormat.parse(orderActualSales.getOpenInvoiceDate());
        //开票时间
       orderCustomer.setInvoiceTime(invoiceTime);
       BigDecimal price  =BigDecimal.valueOf(Long.parseLong(orderActualSales.getSalePrice())) ;
       //开票金额
       orderCustomer.setInvoiceMoney(price);
       //购车金额
       orderCustomer.setBuyAmount(price);
       //vin
       orderCustomer.setVin(orderActualSales.getVin());
       orderCustomer.setCustomerNo(orderActualSalesVO.getCustomerId());
       Boolean flag = orderCustomerService.update(orderCustomer,qw);

      QueryWrapper<OrderActualSales> queryWrapper = new QueryWrapper<>();
      queryWrapper.eq("ORDER_CUSTOMER_NO",orderActualSalesVO.getOrderCustomerNo());
      List<OrderActualSales> list = orderActualSalesService.list(queryWrapper);
      if (list!=null && list.size()>0){
         OrderActualSales actualSales = list.get(0);
         /****************** 将实销信息同步到TMS 能源系统 ************************************************************/
         ApiResult apiResult = pmsSalesInfo2TSP(actualSales);
         if (apiResult != null) return apiResult;
      }

      QueryWrapper<VehicleOffline> wrapper = new QueryWrapper<VehicleOffline>();
      wrapper.eq("VIN",orderActualSalesVO.getVin());
      VehicleOfflineVO vehicleOfflineVO = vehicleOfflineDubboServiceImpl.getVoByVin(orderActualSales.getVin());
      if (vehicleOfflineVO==null){
         return ResponseUtil.fail(-1,"不存在该车辆下线信息");
      }
      else if(StringUtils.isEmpty(vehicleOfflineVO.getVehicleId())) {
         return ResponseUtil.fail(-1, "不存在该车辆下线信息");
      }
      else if(vehicleOfflineVO.getVehiclePurpose()==null) {
         return ResponseUtil.fail(-1,"车辆下线信息,车辆用途为空");
      }
      else if (vehicleOfflineVO.getVehiclePurpose()==3){
         VehicleStockBindVO vehicleStockBindVO = new VehicleStockBindVO();
         vehicleStockBindVO.setVin(orderActualSalesVO.getVin());
         vehicleStockDubboServiceImpl.testDriveOut(vehicleStockBindVO);
      }
      else if(vehicleOfflineVO.getVehiclePurpose()==4){
         VehicleStockBindVO vehicleStockBindVO = new VehicleStockBindVO();
         vehicleStockBindVO.setVin(orderActualSalesVO.getVin());
         vehicleStockDubboServiceImpl.testDriveOut(vehicleStockBindVO);
      }

      return ResponseUtil.ok();
   }

   /**
    * 将实销信息同步到TMS
    * @param actualSales
    * @return
    */
   private ApiResult pmsSalesInfo2TSP(OrderActualSales actualSales) {
      List<CustomCreditReportingVO> customCreditList =  customCreditReportingDubboServiceBase.getByOrderCustomerNo(actualSales.getOrderCustomerNo());
      CustomerSalesInfoVO customerSalesInfoVO = setCustomerSalesInfoTSP(actualSales,customCreditList);
      ApiResult result = null;
      try {
         result = vehicleStockManageDubboServiceImpl.vehicleCustomerSalesInfoPms2Tsp(customerSalesInfoVO);
      } catch (Exception e) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error("  ------- pms2TSP 调用失败 ___实销信息  ---------  ");
         e.printStackTrace();
         return ResponseUtil.fail(-1,"pms2TSP调用失败___实销信息"+e.getMessage());
      }
      if (result.getCode().equals(-1)) {
         TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
         logger.error("  ------- pms2TSP 执行失败 ___实销信息  ---------  ");
         return ResponseUtil.fail(-1,"pms2TSP执行失败___实销信息"+result.getMsg());
      }
      return null;
   }

   /*
      赋值
    */
   private CustomerSalesInfoVO setCustomerSalesInfoTSP(OrderActualSales actualSales,List<CustomCreditReportingVO> customCreditList) {
      CustomerSalesInfoVO customerSalesInfoVO = new CustomerSalesInfoVO();
      customerSalesInfoVO.setOrderNo(actualSales.getOrderCustomerNo());
      customerSalesInfoVO.setCustomerId(actualSales.getCustomerId());//客户ID
      customerSalesInfoVO.setCustomerName(actualSales.getCustomerName());//客户名称
      customerSalesInfoVO.setCustomerType(actualSales.getCustomerType());//客户类型 普通，企业/同CRM
      customerSalesInfoVO.setUnitSocialCreditCode(actualSales.getUnitSocialCreditCode());//统一社会信用代码
      customerSalesInfoVO.setLegalPerson(actualSales.getLegalPerson());//法人
      customerSalesInfoVO.setBuyerPerson(actualSales.getBuyerPerson());//采购人员
      customerSalesInfoVO.setIdType(actualSales.getIdType());//证件类型
      customerSalesInfoVO.setIdNumber(actualSales.getIdNumber());//证件号
      customerSalesInfoVO.setSex(actualSales.getSex());//性别
      if (actualSales.getAge() != null) {
         customerSalesInfoVO.setAge(actualSales.getAge());//年龄
      }
      customerSalesInfoVO.setCompanyPhone(actualSales.getCompanyPhone());//公司电话
      customerSalesInfoVO.setPhone(actualSales.getPhone());//手机电话
      customerSalesInfoVO.setEmail(actualSales.getEmail());//email
      customerSalesInfoVO.setAddress(actualSales.getAddress());//地址
      customerSalesInfoVO.setSaleAssist(actualSales.getSaleAssist());//销售顾问姓名
      customerSalesInfoVO.setCarSaleStatus(actualSales.getCarSaleStatus());//车辆销售状态
      customerSalesInfoVO.setVin(actualSales.getVin());//VIN
      customerSalesInfoVO.setSaleProvince(actualSales.getSaleProvince());//销售省份
      customerSalesInfoVO.setSaleCity(actualSales.getSaleCity());//销售城市
      customerSalesInfoVO.setSaleCountry(actualSales.getSaleCountry());//销售县区
      customerSalesInfoVO.setCarNo(actualSales.getCarNo());//车牌号
      customerSalesInfoVO.setSaleInternetNo(actualSales.getSaleInternetNo());//销售网点编号
      customerSalesInfoVO.setSaleInternetName(actualSales.getSaleInternetName());//销售网点名称
      customerSalesInfoVO.setSalePrice(actualSales.getSalePrice());//销售价格（整车价格）
      customerSalesInfoVO.setPackagePrice(actualSales.getPackagePrice());//选装包价格
      customerSalesInfoVO.setCarUsed(actualSales.getCarUsed());//车辆用途

         customerSalesInfoVO.setCreateRecord_date(actualSales.getCreateRecordDate());//客户建档日期


         customerSalesInfoVO.setOpenInvoice_date(actualSales.getOpenInvoiceDate());//开票日期

      customerSalesInfoVO.setOutTime(actualSales.getOutTime());//出库日期
      customerSalesInfoVO.setInvoiceNo(actualSales.getInvoiceNo());//发票号
      customerSalesInfoVO.setUrgent_name(actualSales.getUrgentName());//紧急联系人
      customerSalesInfoVO.setUrgent_phone(actualSales.getUrgentPhone());//紧急联系人电话
      customerSalesInfoVO.setCompany(actualSales.getCompany());//公司名称
      customerSalesInfoVO.setCompany_addr(actualSales.getCompanyAddr());//公司地址
      customerSalesInfoVO.setDriver_license_type(actualSales.getDriverLicenseType());//准驾类型
      customerSalesInfoVO.setDriver_license_validate(actualSales.getDriverLicenseValidate());//驾驶证件有效期
      //是否购买服务包
      customerSalesInfoVO.setLegalPersonPhone(actualSales.getLegalPersonPhone()); //法人手机
      customerSalesInfoVO.setDriverLicenseNo(actualSales.getDriverLicenseNo()); //驾驶证件号
      customerSalesInfoVO.setOperationAddr(actualSales.getOperationAddr()); //车辆的实际营运地址
      customerSalesInfoVO.setStoreAddr(actualSales.getStoreAddr()); //车辆存放的详细地址
      customerSalesInfoVO.setIsBuyServicePack(actualSales.getIsBuyServicePack());//是否购买服务包
      customerSalesInfoVO.setBatSN(actualSales.getBettaryCode());//电池序列号
      customerSalesInfoVO.setMotSN(actualSales.getMotorNo());//电机序列号
      customerSalesInfoVO.setConSN(actualSales.getElectronicControl());//电控序列号
      if (actualSales.getStatus()!=null){
         customerSalesInfoVO.setCarStatus(String.valueOf(actualSales.getStatus()));
      }
      customerSalesInfoVO.setVehicleCode(actualSales.getVehicleCode());
      customerSalesInfoVO.setVehicleName(actualSales.getVehicleName());

      ApiResult result = orderCustomerDubboServiceImpl.loadByOrderCustomerNo(actualSales.getOrderCustomerNo());
      if (result.getData()!=null){
         OrderCustomer data = (OrderCustomer)result.getData();
         //Guan 添加注释 buytype来零售订单
         customerSalesInfoVO.setBuyType(data.getBuyType());
      }
      customerSalesInfoVO.setUser(actualSales.getUser());
      customerSalesInfoVO.setUserPhone(actualSales.getUserPhone());

      if (customCreditList!=null && customCreditList.size()>0){
         CustomCreditReportingVO customCreditReportingVO = customCreditList.get(0);

         customerSalesInfoVO.setFinanceType(customCreditReportingVO.getFinProduct());// 金融类型,1金融机构,2银行分期
         customerSalesInfoVO.setFinancingInstitution(customCreditReportingVO.getFinancingInsitution());//金融机构 code
         customerSalesInfoVO.setDeadline(customCreditReportingVO.getLeaseTerm());//期限
         if (customCreditReportingVO.getDownPaymentRatio()!=null) {
            customerSalesInfoVO.setDownPayment(customCreditReportingVO.getDownPaymentRatio().toString());//首付比例 百分比数字
         }
         if (customCreditReportingVO.getSuretyAmount()!=null){
            customerSalesInfoVO.setCashDeposit(customCreditReportingVO.getSuretyAmount().toString());//保证金
         }
         if (customCreditReportingVO.getRetentionAmount()!=null){
            customerSalesInfoVO.setBalancePayment(customCreditReportingVO.getRetentionAmount().toString());//尾款
         }
      }

      return customerSalesInfoVO;
   }

   //填充实销数据
   private OrderActualSalesVO setOrderActualSales(OrderCustomerVO orderCustomerVO, CustomerVO customerVO, PartnerVO partnerVO, HandleVehicleVO handleVehicleVO,VehicleOfflineVO vehicleOfflineVO) {
      OrderCustomerDetailVO orderCustomerDetailVO = orderCustomerVO.getOrderCustomerDetailVO();
      OrderActualSalesVO orderActualSalesVO = new OrderActualSalesVO();
//      orderActualSalesVO.setOrderCustomerId("");
      if (StringUtils.isEmpty(orderCustomerVO.getCustomerId())){
         orderActualSalesVO.setCustomerId(orderCustomerVO.getCustomerNo());//客户id 必填
      }else {
         orderActualSalesVO.setCustomerId(orderCustomerVO.getCustomerId());//客户id 必填
      }
      orderActualSalesVO.setCustomerName(orderCustomerVO.getCustomerName());//客户名称 必填
      orderActualSalesVO.setCustomerType(customerVO.getCustomerType());//客户类型 必填

      orderActualSalesVO.setUnitSocialCreditCode(orderCustomerVO.getCompanyCode());//统一社会信用代码 企业必填
      orderActualSalesVO.setLegalPerson("");//法人 非必填
      orderActualSalesVO.setBuyerPerson("");//采购人员 非必填

      orderActualSalesVO.setIdType(orderCustomerVO.getCertType());//证件类型 必填 1居民身份证，2军官证，3港澳台海外地区证件，4企业代码证
      orderActualSalesVO.setIdNumber(orderCustomerVO.getCertNo());//证件号 必填
      orderActualSalesVO.setSex(customerVO.getSex());//性别 必填
      orderActualSalesVO.setAge(customerVO.getAge());//年龄 非必填
      orderActualSalesVO.setCompanyPhone("");//公司电话 必填
      orderActualSalesVO.setPhone(orderCustomerVO.getCustomerMobile());//手机电话 必填
      orderActualSalesVO.setEmail(customerVO.getEmail());//email 必填
      orderActualSalesVO.setAddress(customerVO.getAddr());//地址 必填
      orderActualSalesVO.setSaleAssist(customerVO.getStaffName());//销售顾问姓名 必填
      orderActualSalesVO.setCarSaleStatus("");//车辆销售状态 必填 已上线，已销售/CRM为准
      orderActualSalesVO.setVin(orderCustomerVO.getVin());//VIN 必填
      orderActualSalesVO.setSaleProvince(orderCustomerVO.getProvinceCode());//省 必填
      orderActualSalesVO.setSaleProvinceName(orderCustomerVO.getProvinceName());
      orderActualSalesVO.setSaleCityName(orderCustomerVO.getCityName());
      orderActualSalesVO.setSaleCity(orderCustomerVO.getCityCode());//市 必填
      orderActualSalesVO.setSaleCountryName(orderCustomerVO.getRegionCode());
      orderActualSalesVO.setSaleCountry(orderCustomerVO.getRegionCode());//区 必填
      orderActualSalesVO.setCarNo(orderCustomerVO.getCarNo());//车牌号 非必填
      orderActualSalesVO.setSaleInternetNo(orderCustomerVO.getPartnerCode());//销售网店编号 非必填
      orderActualSalesVO.setSaleInternetName(partnerVO.getPartnerName());//销售网店名称 非必填
      orderActualSalesVO.setSalePrice("");//销售价格 必填
      orderActualSalesVO.setPackagePrice("");//选装包价格 必填
      orderActualSalesVO.setCarUsed("");//车辆用途 非必填
      if (customerVO.getCustCreateTime() != null) {
         orderActualSalesVO.setCreateRecordDate(new SimpleDateFormat("yyyy-MM-dd").format(customerVO.getCustCreateTime()));//客户建档日期 必填
      }
      if (orderCustomerVO.getInvoiceTime() != null) {
         orderActualSalesVO.setOpenInvoiceDate(new SimpleDateFormat("yyyy-MM-dd").format(orderCustomerVO.getInvoiceTime()));//开票日期 必填
      }
      QueryWrapper<PmsVehicleStock> queryWrapper1 = new QueryWrapper<>();
      queryWrapper1.eq("VIN",vehicleOfflineVO.getVin());
      PmsVehicleStock vehicleStock = vehicleStockMService.getOne(queryWrapper1);
      Date outStockDate = vehicleStock.getOutStockDate();
      if (outStockDate != null) {
         orderActualSalesVO.setOutTime(new SimpleDateFormat("yyyy-MM-dd").format(outStockDate));//出库日期 必填
      }
      orderActualSalesVO.setInvoiceNo(orderCustomerVO.getInvoiceCode());//发票号 必填
      orderActualSalesVO.setUrgentName("");//紧急联系人 非必填
      orderActualSalesVO.setUrgentPhone("");//紧急联系人电话 非必填
      orderActualSalesVO.setCompany(orderCustomerVO.getCompanyName());//公司名称 非必填
      orderActualSalesVO.setCompanyAddr("");//公司地址 非必填
      orderActualSalesVO.setDriverLicenseType("");//准驾类型 非必填
      orderActualSalesVO.setDriverLicenseValidate("");//驾驶证有效期 非必填
      orderActualSalesVO.setIsBuyServicePack("");//是否购买服务包 必填
      orderActualSalesVO.setBettaryCode(vehicleOfflineVO.getBettaryCode());//电池序列号 必填
      orderActualSalesVO.setMotorNo(vehicleOfflineVO.getMotorCode());//电机号  必填
      orderActualSalesVO.setEnguneNo(vehicleOfflineVO.getMotorCode());//电机序列号  必填
      orderActualSalesVO.setElectronicControl(vehicleOfflineVO.getElectronicControl());//电控序列号  必填
      orderActualSalesVO.setLegalPersonPhone("");//法人手机  非必填
      orderActualSalesVO.setDriverLicenseNo("");//驾驶证件号  必填
      orderActualSalesVO.setOperationAddr("");//实际营运地址  非必填
      orderActualSalesVO.setStoreAddr("");//车辆存放的详细地址  非必填
      orderActualSalesVO.setStatus(0);
//      orderActualSalesVO.setCarStatus();
             /*1车辆排产中（车架号/下总装）
               2车辆已生产
               3车辆运输中
               4车辆已到店
               5订单可签约
               6车辆可提车
               7车辆已租出
               8车辆已入库
               9车辆可上架"*/
      orderActualSalesVO.setPartnerCode(orderCustomerVO.getPartnerCode());//渠道商编号
      orderActualSalesVO.setPartnerPhone(partnerVO.getMobilePhone());//渠道商手机
      orderActualSalesVO.setPartnerAddr(partnerVO.getAddr());//渠道商地址
      orderActualSalesVO.setPartnerLinkMan(partnerVO.getLinkMan());//渠道商联系人
      orderActualSalesVO.setBrandCode(orderCustomerVO.getProductPackageId());//车系代码
      if (StringUtils.isNotEmpty(orderCustomerDetailVO.getVehicleName())){
         String[] arr = orderCustomerDetailVO.getVehicleName().split("/");
         orderActualSalesVO.setBrandName(arr[0]);//车系名称
      }
      orderActualSalesVO.setVehicleCode(orderCustomerVO.getProductPackageId());//车型代码
      orderActualSalesVO.setVehicleName(orderCustomerDetailVO.getVehicleName());//车型名称
      orderActualSalesVO.setColorOutCode(orderCustomerDetailVO.getColorCodeOut());//外饰代码
      orderActualSalesVO.setColorOutName(orderCustomerDetailVO.getColorNameOut());//外饰名称
      orderActualSalesVO.setColorInnerCode(orderCustomerDetailVO.getColorCodeIn());//内饰代码
      orderActualSalesVO.setColorInnerName(orderCustomerDetailVO.getColorNameIn());//内饰名称
      orderActualSalesVO.setCustomPackCode(orderCustomerDetailVO.getCustomPackCode());//选装包代码
      if (StringUtils.isNotEmpty(orderCustomerDetailVO.getCustomPackName())){
         String s = orderCustomerDetailVO.getCustomPackName().replaceAll("\"", "");
         String packName = s.substring(1, s.length() - 1);
         orderActualSalesVO.setCustomPackName(packName);//选装包名称
      }
      orderActualSalesVO.setFrontMoney(new BigDecimal("0"));//定金
      orderActualSalesVO.setPrice(new BigDecimal("0"));//价格
      orderActualSalesVO.setPriceTypeName("");//价格折扣类型
      orderActualSalesVO.setPriceTypeValue("");//价格折扣值
      orderActualSalesVO.setSettlementTypeCode("");//结算类型
      orderActualSalesVO.setSpecialConfig("");//特殊配置标识
      orderActualSalesVO.setLicensePlateNumber(orderCustomerVO.getCarNo());//牌照号
      orderActualSalesVO.setYearlyInspectionDate("");//年检日期
      orderActualSalesVO.setYearlyInspectionCycle("");//年检周期
      orderActualSalesVO.setCertNo("");//合格证号
      orderActualSalesVO.setInterchange(handleVehicleVO.getFinishDate());//交车日期
      orderActualSalesVO.setCardDate(new Date());//上牌日期
      orderActualSalesVO.setInsuranceDateRange("");//保险起始日期
      orderActualSalesVO.setInvoiceVehicleType("");//公告车型号
      orderActualSalesVO.setBankAccount("");//开户帐号
      orderActualSalesVO.setBank("");//开户行
      orderActualSalesVO.setInvoiceBo(orderCustomerVO.getInvoiceCode());//发票编号
      orderActualSalesVO.setInvoiceRate(new BigDecimal("0"));//发票税率
      orderActualSalesVO.setInsurerNo("");//保险公司
      orderActualSalesVO.setInsurerType("");//购买险种
      orderActualSalesVO.setOrderCustomerNo(orderCustomerVO.getOrderNo());//零售单编号
      return orderActualSalesVO;
   }

   /**
    * 保险-->PMS 保险公司通过VIN和市编码获取实销信息
    *
    * @param orderActualSalesReqVO vin码,市编码
    * @return
    */
   @Override
   public ApiResult orderActualSales2Insurance(OrderActualSalesReqVO orderActualSalesReqVO) {
      if (StringUtils.isEmpty(orderActualSalesReqVO.getCityCode())) return ResponseUtil.fail(-1,"市编码为空");
      if (StringUtils.isEmpty(orderActualSalesReqVO.getVin())) return ResponseUtil.fail(-1,"VIN为空");

      QueryWrapper<OrderActualSales> queryWrapper = new QueryWrapper<>();
      HashMap<String, Object> map = new HashMap<>();
      map.put("SALE_CITY", orderActualSalesReqVO.getCityCode());
      map.put("VIN", orderActualSalesReqVO.getVin());
      map.put("IS_REPORTED",1 );
      queryWrapper.allEq(map);
      List<OrderActualSales> list = orderActualSalesService.list(queryWrapper);
      if (list != null && list.size() > 1) return ResponseUtil.fail(-1, "该VIN存在多条实销数据");
      VehicleCertVO vehicleCertVO = vehicleCertDubboServiceImpl.getByVin(orderActualSalesReqVO.getVin());
      if (vehicleCertVO==null || StringUtils.isEmpty(vehicleCertVO.getVehicleCertId())) return ResponseUtil.fail(-1,"不存在该合格证车型");
      //(北京 上海 必须查询实销信息，其他可以查询订单信息)
      OrderActualSalesRespVO orderActualSalesRespVO = null;
      if (DictConstant.CITY_CODE_SHANGHAI.equals(orderActualSalesReqVO.getCityCode()) || DictConstant.CITY_CODE_BEIJING.equals(orderActualSalesReqVO.getCityCode())) {
         if (list != null &&list.size() > 0) {
            OrderActualSales orderActualSales = list.get(0);
            orderActualSalesRespVO= setOrderActualSalesRespVO(orderActualSales,vehicleCertVO);
            return ResponseUtil.ok(orderActualSalesRespVO);
         }else {
            return ResponseUtil.fail(110000,"不存在该实销信息");
         }
      } else {
         if (list != null &&list.size() > 0) {
            OrderActualSales orderActualSales = list.get(0);
            orderActualSalesRespVO = setOrderActualSalesRespVO(orderActualSales,vehicleCertVO);
            return ResponseUtil.ok(orderActualSalesRespVO);
         }else {

            OrderCustomerVO vo = new OrderCustomerVO();
            vo.setCityCode(orderActualSalesReqVO.getCityCode());
            vo.setVin(orderActualSalesReqVO.getVin());
            List<OrderActualSalesRespVO> orderActualSalesRespVOList =  orderCustomerDubboServiceImpl.listByVinAndCity(vo);
            if (orderActualSalesRespVOList!=null && orderActualSalesRespVOList.size()>1) return ResponseUtil.fail(-1,"该VIN存在多条订单");
            if(orderActualSalesRespVOList!=null && orderActualSalesRespVOList.size()>0){
               orderActualSalesRespVO =orderActualSalesRespVOList.get(0);
               orderActualSalesRespVO.setVehicleCode(vehicleCertVO.getVehicleCode());
            }
         }
      }
      if (orderActualSalesRespVO==null)  return ResponseUtil.fail(110000,"不存在该实销信息");
      return ResponseUtil.ok(orderActualSalesRespVO);
   }

   private OrderActualSalesRespVO setOrderActualSalesRespVO(OrderActualSales orderActualSales,VehicleCertVO vehicleCertVO) {
      OrderActualSalesRespVO orderActualSalesRespVO = new OrderActualSalesRespVO();
      orderActualSalesRespVO.setCustomerId(orderActualSales.getCustomerId());//客户ID
      orderActualSalesRespVO.setCustomerName(orderActualSales.getCustomerName());//客户名称
      if (StringUtils.isNotEmpty(orderActualSales.getCustomerType())){
         orderActualSalesRespVO.setCustomerType(Integer.valueOf(orderActualSales.getCustomerType()));//客户类型 (普通，企业/同CRM) 1车主2线索6潜客
      }

      orderActualSalesRespVO.setUnitSocialCreditCode(orderActualSales.getUnitSocialCreditCode());//统一社会信用代码
      if (StringUtils.isNotEmpty(orderActualSales.getIdType())){//证件类型 1居民身份证，2军官证，3港澳台海外地区证件，4企业代码证
         orderActualSalesRespVO.setIdType(Integer.valueOf(orderActualSales.getIdType()));
      }
      orderActualSalesRespVO.setIdNumber(orderActualSales.getIdNumber());//证件号
      orderActualSalesRespVO.setPhone(orderActualSales.getPhone());//手机电话
      orderActualSalesRespVO.setEmail(orderActualSales.getEmail());//email
      orderActualSalesRespVO.setVin(orderActualSales.getVin());
      orderActualSalesRespVO.setSaleProvince(orderActualSales.getSaleProvince());//销售省份
      orderActualSalesRespVO.setSaleCity(orderActualSales.getSaleCity());//销售城市
      orderActualSalesRespVO.setSaleCountry(orderActualSales.getSaleCountry());//销售县区
      orderActualSalesRespVO.setOpenInvoice_date(orderActualSales.getOpenInvoiceDate());//开票日期
      orderActualSalesRespVO.setInvoiceNo(orderActualSales.getInvoiceNo());//发票号
      orderActualSalesRespVO.setMotSN(orderActualSales.getEnguneNo());//电机序列号
      orderActualSalesRespVO.setVehicleCode(vehicleCertVO.getVehicleCode());//车辆型号 型普15位码 (mes给的合格证公告车型/备案过的合格证型号)
      ApiResult apiResult = orderCustomerDubboServiceImpl.loadByOrderCustomerNo(orderActualSales.getOrderCustomerNo());
      if (apiResult.getData()!=null){
         OrderCustomer data = (OrderCustomer) apiResult.getData();
         orderActualSalesRespVO.setBuyType(data.getBuyType());//购车方案 ('1-->购车 2-->体验车 3-->畅想车)
      }
      orderActualSalesRespVO.setCityCode(orderActualSales.getSaleCity());//购车城市/提车城市
      orderActualSalesRespVO.setSalePrice(orderActualSales.getSalePrice());//销售价格（整车价格）
      orderActualSalesRespVO.setBuyCarType(orderActualSales.getBuyCarType());//购车类型/是否购买保险 (Y/N)
      List<CustomCreditReportingVO> list = customCreditReportingDubboServiceBase.getByOrderCustomerNo(orderActualSales.getOrderCustomerNo());
      if (list!=null && list.size()>0){
         CustomCreditReportingVO customCreditReportingVO = list.get(0);
         orderActualSalesRespVO.setFinancingInstitution(customCreditReportingVO.getFinancingInsitution());//金融机构编号
         PartnerVO partnerVO = partnerDubboServiceImpl.getCasById(customCreditReportingVO.getFinancingInsitution());
         orderActualSalesRespVO.setFinancingInstitutionName(partnerVO.getPartnerName());
      }
      String partnerCode = orderActualSales.getPartnerCode();
      orderActualSalesRespVO.setPartnerCode(partnerCode);
      if (StringUtils.isNotEmpty(partnerCode)){
         PartnerVO partnerVO = partnerDubboServiceImpl.getCasById(partnerCode);
         if (partnerVO!=null && StringUtils.isNotEmpty(partnerVO.getPartnerId())){
            orderActualSalesRespVO.setPartnerAddress(partnerVO.getAddr());
            orderActualSalesRespVO.setPartnerName(partnerVO.getPartnerName());
         }
      }
      return orderActualSalesRespVO;
   }
}
